/**
 * 
 */
package com.easidea.tim.entity.inventory;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springside.core.dao.extend.Undeletable;

import com.easidea.tim.entity.BaseEntity;
import com.easidea.tim.entity.purchase.PurchaseOrder;
import com.easidea.tim.entity.saleorder.SaleOrder;

/**
 * 出入库
 * @author Harrison
 *
 */
@Entity(name="tim_inventory_checkinout")
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Cache(region="tim_inventory_checkinout",usage=CacheConcurrencyStrategy.READ_WRITE)
@Undeletable(status="deleted")
public class CheckInOut extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9058271446589450714L;
	
	
	public static short CHECKINOUT_DIRECTION_CHECKIN = 1; //入库
	public static short CHECKINOUT_TYPE_CHECKIN_PURCHASE = 1; //采购入库
	public static short CHECKINOUT_TYPE_CHECKIN_RETURN = 2; //退货入库
	public static short CHECKINOUT_TYPE_CHECKIN_SAMPLE = 3; //剪样新增入库（产品-->剪样）
	public static short CHECKINOUT_TYPE_CHECKIN_SAMPLE_SALES_RETURN = 4; //剪样销售退回入库
	public static short CHECKINOUT_TYPE_CHECKIN_SAMPLE_USES_RETURN = 5; //剪样领用退回入库
	public static short CHECKINOUT_TYPE_CHECKIN_INVENTORY_PROFIT = 6; //盘盈调整
	public static short CHECKINOUT_TYPE_CHECKIN_TRANSFORM_PRODUCT = 7; // 转换产品入库

	public static short CHECKINOUT_DIRECTION_CHECKOUT = -1; //出库
	public static short CHECKINOUT_TYPE_CHECKOUT_PRODUCT_SALES = -1; // 销售出库
	public static short CHECKINOUT_TYPE_CHECKOUT_PURCHASE_RETURN = -2; //采购退货出库
	public static short CHECKINOUT_TYPE_CHECKOUT_SAMPLE_SALES = -3; // 剪样销售出库
	public static short CHECKINOUT_TYPE_CHECKOUT_SAMPLE_USES = -4; // 剪样领用
	public static short CHECKINOUT_TYPE_CHECKOUT_TRANSFORM_SAMPLE = -5; // 产品转化剪样出库
	public static short CHECKINOUT_TYPE_CHECKOUT_INVENTORY_LOSS = -6; //盘亏调整
	public static short CHECKINOUT_TYPE_CHECKOUT_TRANSFORM_PRODUCT = -7; //剪样转化产品出库

	private Double piNumSummary; //总计匹数
	private Double meterNumSummary; //总计米数
	
	private Short type; //类型
	private Short direction; //业务方向（出库、入库）
	
	private PurchaseOrder purchaseOrder; // 关联采购订单
	private SaleOrder saleOrder; // 关联销售订单
	private List<CheckInOutItem> items; // 出入库详细信息
	private String description; // 简单描述
	private String state;//出入库单据状态，0为初始状态，1为允许发货状态，2为发货完毕状态
	/**
	 * @return the type
	 */
	@Column(name="type",nullable=false)
	public Short getType() {
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType(Short type) {
		this.type = type;
	}
	/**
	 * @return the direction
	 */
	@Column(name="direction",nullable=false)
	public Short getDirection() {
		return direction;
	}
	/**
	 * @param direction the direction to set
	 */
	public void setDirection(Short direction) {
		this.direction = direction;
	}
	/**
	 * @return the purchaseOrder
	 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="purchase_order_id",nullable=true)
	public PurchaseOrder getPurchaseOrder() {
		return purchaseOrder;
	}
	/**
	 * @param purchaseOrder the purchaseOrder to set
	 */
	public void setPurchaseOrder(PurchaseOrder purchaseOrder) {
		this.purchaseOrder = purchaseOrder;
	}
	/**
	 * @return the saleOrder
	 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="sale_order_id",nullable=true)
	public SaleOrder getSaleOrder() {
		return saleOrder;
	}
	/**
	 * @param saleOrder the saleOrder to set
	 */
	public void setSaleOrder(SaleOrder saleOrder) {
		this.saleOrder = saleOrder;
	}
	/**
	 * @return the items
	 */
	@OneToMany(fetch=FetchType.LAZY,mappedBy="checkInOut")
	public List<CheckInOutItem> getItems() {
		return items;
	}
	/**
	 * @param items the items to set
	 */
	public void setItems(List<CheckInOutItem> items) {
		this.items = items;
	}
	/**
	 * @return the description
	 */
	@Column(name="description", length=3000)
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}


	/**
	 * @return the piNumSummary
	 */
	@Column(name="pi_num_summary",nullable=false,length=5,precision=0)
	public Double getPiNumSummary() {
		return piNumSummary;
	}


	/**
	 * @param piNumSummary the piNumSummary to set
	 */
	public void setPiNumSummary(Double piNumSummary) {
		this.piNumSummary = piNumSummary;
	}


	/**
	 * @return the meterNumSummary
	 */
	@Column(name="meter_num_summary", nullable=false,length=8,precision=2 )
	public Double getMeterNumSummary() {
		return meterNumSummary;
	}


	/**
	 * @param meterNumSummary the meterNumSummary to set
	 */
	public void setMeterNumSummary(Double meterNumSummary) {
		this.meterNumSummary = meterNumSummary;
	}
	
	@Column(name="state")
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	
	
}
